/*

Copyright 2007 Renaun Erickson (http://renaun.com)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

@ignore
*/
package asfslib.api.familytree.v1
{

/**
 * 	Name Assertion containing forms and pieces of a name
 */
public class NameAssertion extends Assertion
{

    //--------------------------------------------------------------------------
    //
    //  Constants
    //
    //--------------------------------------------------------------------------
    
    /**
     * 	The name assertion piece constant "Prefix"
     */
    public static const PIECE_PREFIX:String = "Prefix";
    
    /**
     * 	The name assertion piece constant "Suffix"
     */
    public static const PIECE_SUFFIX:String = "Suffix";
    
    /**
     * 	The name assertion piece constant "Given"
     */
    public static const PIECE_GIVEN:String = "Given";
    
    /**
     * 	The name assertion piece constant "Family"
     */
    public static const PIECE_FAMILY:String = "Family";
    
    /**
     * 	The name assertion piece constant "Other"
     */
    public static const PIECE_OTHER:String = "Other";

	/**
	 * 	Static method to parse NameAssertion XML
	 */
	public static function parseXML(xml:XML):NameAssertion
    {
    	if (xml.namespace("") != undefined) 
		{
		    default xml namespace = xml.namespace("");
		} 
		
		var assertion:NameAssertion = new NameAssertion();
		assertion.id = xml.@id;
		assertion.contributor = xml.@contributor;
		assertion.disputing = xml.@disputing;
		//assertion.modifiable = xml.@modifiable;
		assertion.modified = xml.@modified;
		//assertion.submitter = xml.@submitter;
		assertion.type = xml.@type;
		assertion.version = xml.@version;
		
		assertion.forms = xml.forms.form;
		
		default xml namespace = new Namespace("");
		
    	return assertion;
    }
    
    //--------------------------------------------------------------------------
    //
    //  Properties
    //
    //--------------------------------------------------------------------------    
	
    //----------------------------------
    //  type
    //----------------------------------

    /**
     *  @private
     *  Storage for the type property.
     */
    private var _type:String = "";

    /**
     *  The type property
     *
     *  @default  = ""
     */
    public function get type():String
    {
        return _type;
    }

    /**
     *  @private
     */
    public function set type(value:String):void
    {
        _type = value;
    }


    //----------------------------------
    //  forms
    //----------------------------------

    /**
     *  @private
     *  Storage for the forms property.
     */
    private var _forms:XMLList;

    /**
     *  The forms property
     *
     *  @default 
     */
    public function get forms():XMLList
    {
        return _forms;
    }

    /**
     *  @private
     */
    public function set forms(value:XMLList):void
    {
        _forms = value;
    }

    //----------------------------------
    //  fullText
    //----------------------------------

    /**
     *  The fullText property
     *
     *  @default
     */
    public function get fullText():String
    {
        return forms[0].fullText;
    }

    //----------------------------------
    //  script
    //----------------------------------

    /**
     *  The script property
     *
     *  @default
     */
    public function get script():String
    {
        return forms[0].@script;
    } 

    //----------------------------------
    //  prefix
    //----------------------------------

    /**
     *  The prefix property
     *
     *  @default
     */
    public function get prefix():String
    {
        return forms[0].pieces.piece.(@type == NameAssertion.PIECE_PREFIX).value;
    }   

    //----------------------------------
    //  suffix
    //----------------------------------

    /**
     *  The suffix property
     *
     *  @default
     */
    public function get suffix():String
    {
        return forms[0].pieces.piece.(@type == NameAssertion.PIECE_SUFFIX).value;
    }   

    //----------------------------------
    //  given
    //----------------------------------

    /**
     *  The given property
     *
     *  @default
     */
    public function get given():String
    {
        return forms[0].pieces.piece.(@type == NameAssertion.PIECE_GIVEN).value;
    }  

    //----------------------------------
    //  family
    //----------------------------------

    /**
     *  The family property
     *
     *  @default
     */
    public function get family():String
    {
        return forms[0].pieces.piece.(@type == NameAssertion.PIECE_FAMILY).value;
    } 

    //----------------------------------
    //  other
    //----------------------------------

    /**
     *  The other property
     *
     *  @default
     */
    public function get other():String
    {
        return forms[0].pieces.piece.(@type == NameAssertion.PIECE_OTHER).value;
    } 

    //----------------------------------
    //
    //  Methods
    //
    //----------------------------------
	
	/**
	 * 	Make a clone of this instance
	 */
    override public function clone():Assertion
    {
    	var target:EventAssertion = new EventAssertion();
        copy(target);
        return target;
    }	

	/**
	 * 	Make a clone of this instance
	 */
    override protected function copy(target:Assertion):void
    {
    	super.copy(target);
    	var eventAssertion:NameAssertion = target as NameAssertion;
    	
        eventAssertion.type = type;
        eventAssertion.forms = forms;
    }


}
}
